package nec.aagent.core.db;

import android.location.Location;

import com.j256.ormlite.field.DatabaseField;

public class LocationDb {
    @DatabaseField(generatedId = true)
    long genId;
    @DatabaseField
    String provider;
    @DatabaseField
    double latitude;
    @DatabaseField
    double longitude;
    @DatabaseField
    float accuracy;
    @DatabaseField
    float speed; // unit: m/s
    @DatabaseField
    long time;
    @DatabaseField
    double altitude;
    @DatabaseField
    float bearing;

    public LocationDb() {
    }

    public LocationDb(Location location) {
        provider = location.getProvider();
        altitude = location.getAltitude();
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        accuracy = location.getAccuracy();
        speed = location.getSpeed();
        bearing = location.getBearing();
    }

    public static Location convert(LocationDb dbObject) {
        Location location = new Location(dbObject.provider);
        location.setAccuracy(dbObject.accuracy);
        location.setAltitude(dbObject.altitude);
        location.setBearing(dbObject.bearing);
        location.setLatitude(dbObject.latitude);
        location.setLongitude(dbObject.longitude);
        location.setSpeed(dbObject.speed);
        location.setTime(dbObject.time);
        return location;
    }
}
